package kk.learn.rabbitmq.dlxdemo.controller;

import kk.learn.rabbitmq.dlxdemo.model.Result;
import kk.learn.rabbitmq.dlxdemo.service.IOrderService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *
 * </p>
 *
 * @author KK
 * @since 2021-10-30
 */
@RestController
public class OrderController {

    private final IOrderService orderService;

    public OrderController(IOrderService orderService) {
        this.orderService = orderService;
    }


    @RequestMapping("/order")
    public Result order(
            @RequestParam("userId") Long userId,
            @RequestParam("product") String product
                        ) {
        Long order = orderService.order(userId, product);

        return Result.ok(order);
    }



    @RequestMapping("/pay")
    public Result pay(
            @RequestParam("userId") Long userId,
            @RequestParam("orderId") Long orderId
    ) {

        String pay = orderService.pay(userId, orderId);

        return Result.ok(pay);
    }



    @RequestMapping("/orders")
    public Result orders(
            @RequestParam("userId") Long userId
    ) {


        return Result.ok(orderService.orders(userId));
    }


}
